import http from './__http__'
import storage from '@/util/storage'
const productInfo = storage.local.get('productInfo')


export const sysParamsApi = () => {
  return http.request({
    url: '/sysParams'
  })
}

// export const loginApi = (data) => {
//   return http.request({
//     url: '/login',
//     method: 'post',
//     data
//   })
// }

export const loginApi = (data) => {
  let requests = [];
  let ip = productInfo.ip.slice(0, productInfo.ip.lastIndexOf('.'));
  for(let i=1; i<128;  i++){
    const baseURL = 'http://' + ip + '.' + i + ':' + productInfo.port;

    requests.push(
      Promise.resolve(
        http.request({
          url: baseURL + '/login',
          method: 'post',
          data
        })
      )
    )
  }

  return Promise.all(requests).then(res=>{
    let result = [];
    if(res.code ==0){
      result.push(res.data);
    }
    return {
      code: 0,
      data: result[0]||{}
    }
  })
}
export const logoutApi = () => {
  return http.request({
    url: '/logout',
    method: 'post',
    data
  })
}